Hyper-V Network Virtualization Cookbook by Ryan Boud

Hyper-V Network Virtualization Cookbook by Ryan Boud

Author:Ryan Boud [Boud, Ryan]
Language: eng
Format: epub, pdf
Publisher: Packt Publishing
Published: 2014-11-27T22:00:00+00:00


It is important to know which network adapter is connected to which network interface. In the wizard, there are the following three Ethernet adapters listed at the moment:Ethernet2

Ethernet3

Ethernet4

None of these are particularly useful. The following PowerShell script will obtain all the information about the gateway VM from VMM, determine the VM Networks each NIC is attached to and rename the NIC in the VM with the appropriate name. The code is as follows:

#Hashtable of VM Networks and the names the NICs should be inside the Gateway VM $NicNames =@{ "Host-Management" ="Management"; "External (NAT)" ="External"; "" ="TenantNetworks" } #Get the VM from VMM, not from Hyper-V $GatewayVM = Get-SCVirtualMachine -Name HNVGateway1 #Iterate through each entry in the Hashtable ForEach($Key in $NicNames.Keys){ #Find the Network Adapter's MAC Address in VMM that is connected to #the VM Network. As the Tenant Network Adapter is not attached to a #VM Network it must be dealt with carefully $VNAMacAddress = ($GatewayVM.VirtualNetworkAdapters | Where-Object{ #Check for an actual value if($_.VMNetwork.Name){ if($_.VMNetwork.Name -eq $key){ $True } } #check for the Tenant NIC elseif(!($_.VMNetwork.Name) -and !($key)){ $True } }).MACAddress Invoke-Command -ComputerName $GatewayVM.ComputerName -ScriptBlock { Param($LocalMacAddress, $NewNicName) #Change the format of the MAC Address $LocalMacAddress = $LocalMacAddress -replace ":","-" #Find the NIC based on the MAC address obtained from VMM $NIC = Get-NetAdapter | Where-Object { $_.MacAddress -eq $LocalMacAddress} #Get the WMI object based on the NIC's current name $wmi = Get-WmiObject -Class Win32_NetworkAdapter -Filter "NetConnectionID = ""$($NIC.Name)""" #Change the NIC's name to the correct name $wmi.NetConnectionID = $NewNicName $wmi.Put() } -ArgumentList $VNAMacAddress,$NicNames.Item($Key) }



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.